/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package poker.geneticAlgorithm;

import java.util.List;
import poker.game.Game;
import poker.game.Player;

/**
 *
 * @author Benjamin L. Brodie <blbrodie@gmail.com>
 */
public class PokerGameSelection implements Selection<Individual<Double>>{
    int numberOfGames;
    Game game;
    Player playerA;
    Player playerB;
    

    
    @Override
    public Individual<Double> selectFrom(List<Individual<Double>> individuals) {
        playerA = new Player(individuals.get(0).getList());
        playerB = new Player(individuals.get(1).getList());
        
        for (int i = 0; i < numberOfGames; i++){
            game = new Game(playerA, playerB);
            
            game.play();
        }
        
        if (playerA.getTotalChipsWon() > playerB.getTotalChipsWon()){
            System.out.println("player A won: " + playerA.getTotalChipsWon() + " chips");
            return new WeightsIndividual(playerA.getWeights());
        }
        else if (playerB.getTotalChipsWon() < playerB.getTotalChipsWon()){
            System.out.println("player B won: " + playerA.getTotalChipsWon() + " chips");
            return new WeightsIndividual(playerB.getWeights());
        }
        else{
            System.out.println("Tie: " + "both won " + playerA.getTotalChipsWon());
            return new WeightsIndividual(playerA.getWeights());
        }
        
        
        
        
    }
    
    public PokerGameSelection(int numberOfGames){
        this.numberOfGames = numberOfGames;
    }
    
    
    
    
}
